package com.situ.day11;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class ExceptionDemo {

    public static void main1(String[] args) {
        String str = "诺基亚xxxx";
        System.out.println("HTC" + str.substring(3));
    }

    @Test
    public void tes1() {
//        int @23 = 23;
        System.out.println(3 / 0);
    }

    @Test
    public void test2() {
        // 文件的输入流
        // 编译时异常   "未雨绸缪"
        try {
            FileInputStream fileInputStream = new FileInputStream("java.txt");
            fileInputStream.read();
            // FileNotFoundException extends IOException
            //FileNotFoundException fileNotFoundException = new FileNotFoundException();
            //FileNotFoundException e = fileNotFoundException;
            //IOException e = fileNotFoundException;
        }  catch (FileNotFoundException e) {
            // Exception 'java.io.FileNotFoundException' has already been caught
            e.printStackTrace();
        } catch (IOException e) { // IO:Input Output 输入输出
            e.printStackTrace();
        } finally {

        }

        System.out.println("ExceptionDemo.test2");
    }

    @Test
    public void test3() {
        try {
            FileInputStream fileInputStream = new FileInputStream("java.txt");
            fileInputStream.read();
        } catch (Exception e) { // IO:Input Output 输入输出
            e.printStackTrace();
        } finally {

        }
    }

    public static void main(String[] args) {
        ExceptionDemo exceptionDemo = new ExceptionDemo();
        try {
            exceptionDemo.testTrowException();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        System.out.println("ExceptionDemo.main");
    }

    public void testTrowException() throws FileNotFoundException {
        FileInputStream fileInputStream = new FileInputStream("java.txt");
    }

}
